package com.ms.oschina.ui.dialog;

import com.ms.oschina.R;
import com.ms.oschina.util.UiUtils;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public abstract class QuickOptionDialog extends Dialog {

	public interface OnQuickOptionformClick {
		void onQuickOptionClick(int id);
	}

	private OnQuickOptionformClick mListener;
	private int gravity = Gravity.BOTTOM;
	private boolean isfillScreen = true;

	@SuppressLint("InflateParams")
	/**
	 * 
	 * @param context
	 * @param defStyle 弹出对话框动画
	 */
	public QuickOptionDialog(Context context, int defStyle) {
		super(context, defStyle);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		super.setContentView(getContentView());

	}

	public abstract View getContentView();

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		// 显示在哪个位置
		
		getWindow().setGravity(gravity);
		WindowManager m = getWindow().getWindowManager();
		Display d = m.getDefaultDisplay();
		WindowManager.LayoutParams p = getWindow().getAttributes();
		int width = d.getWidth();
		if(isfillScreen){
			p.width = width;// 宽度填满屏幕
		}else{
			int dimensionPixelSize = UiUtils.getDimensionPixelSize(R.dimen.space_60);
			p.width = width-dimensionPixelSize;
		}
		getWindow().setAttributes(p);
	}

	public void isfillScreen(boolean isfillScreen) {
		this.isfillScreen = isfillScreen;
	}

	public void setOnQuickOptionformClickListener(OnQuickOptionformClick lis) {
		mListener = lis;
	}

	public void setGravity(int gravity) {
		this.gravity = gravity;
	}
}
